package top.zywork.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import top.zywork.constant.CommonConstant;
import top.zywork.dos.SchoolParcelDO;
import top.zywork.dos.SchoolPlaceDO;
import top.zywork.dto.PagerDTO;
import top.zywork.mapper.SchoolParcelMapper;
import top.zywork.query.SchoolParcelQuery;
import top.zywork.service.SchoolParcelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author
 * @since 2020-10-13
 */
@Service
public class SchoolParcelServiceImpl extends ServiceImpl<SchoolParcelMapper, SchoolParcelDO> implements SchoolParcelService {


    @Override
    public SchoolParcelDO checkParcel(Long schoolId, Long id) {
        return baseMapper.selectOne(new QueryWrapper<SchoolParcelDO>()
                .eq("is_active", CommonConstant.IS_ACTIVE_TRUE)
                .eq("school_id",schoolId)
                .eq("id",id));
    }

    @Override
    public PagerDTO listAllByCondition(SchoolParcelQuery schoolParcelQuery) {
        List<Object> objects = baseMapper.listAllByCondition(schoolParcelQuery);
        Long aLong = baseMapper.countByCondition(schoolParcelQuery);
        return PagerDTO.builder().rows(objects).total(aLong).build();
    }

    @Override
    public PagerDTO listPageByCondition(SchoolParcelQuery schoolParcelQuery) {
        List<Object> objects = baseMapper.listPageByCondition(schoolParcelQuery);
        Long aLong = baseMapper.countByCondition(schoolParcelQuery);
        return PagerDTO.builder().rows(objects).total(aLong).build();
    }
}
